<template>
  <mu-container class="pos-r">
    <mu-row class="padt10">
      <mu-paper :z-depth="1" style="width: 100%" class="round5 pad5">
        <mu-flex align-items="center">
          <mu-flex>
            <mu-button icon @click="$goback()">
              <mu-icon value="arrow_back"></mu-icon>
            </mu-button>
          </mu-flex>
          <mu-flex fill><h3>智能录入</h3></mu-flex>
          <mu-flex>
            <div class="padr10">
              <mu-button small fab color="primary" @click="create()">
                <mu-icon value="save"></mu-icon>
              </mu-button>
            </div>
          </mu-flex>
        </mu-flex>
      </mu-paper>
    </mu-row>
    <mu-row class="padt10 pos-r">
      <mu-paper class="pad10" style="width: 100%" :z-depth="1">
        <div class="pad10">
          <div>
            <!--        表单-->
            <formCreator ref="form" :form.sync="form" :items="items"></formCreator>
            <!--        表单-->
            <mu-row :gutter="true">
              <mu-col span="12">
                <mu-text-field v-model="text" class="" label="数据" placeholder="粘入文本" multi-line :rows="10" :rows-max="10" full-width></mu-text-field>
              </mu-col>
            </mu-row>
            <mu-row>
              <mu-button full-width @click="submit()">分析</mu-button>
            </mu-row>
          </div>
          <div>
            <mu-paper :z-depth="2" style="width: 100%" class="mar5" v-for="item,index in questions" :key="index">
              <div class="bdda pad2">{{item.title}}</div>
              <div class="bdda pad2" v-for="str,idx in item.choice" :key="idx">{{latters[idx]}}:{{str}}</div>
              <div class="bdda pad2">{{item.choiceSet}}</div>
              <div class="bdda pad2">{{item.intro}}</div>
              <div>
                <mu-button @click="importQ(index)">导入</mu-button>
              </div>
            </mu-paper>
          </div>
        </div>
      </mu-paper>
    </mu-row>
  </mu-container>

</template>

<script>
import api from '@/assets/js/api'
import formCreator from '@/components/FormCreator/Creator/Creator'
import entity from '@/components/FormItem/entity'
import entityViewer from '@/components/FormItem/entityViewer'
import com from '../../../assets/js/com'

export default {
  name: 'Ai',
  components: {formCreator, entity, entityViewer},
  data () {
    return {
      id: undefined,
      active: 0,
      text: '',
      form: {},
      items: {},
      questions: [],
      latters: ['A', 'B', 'C', 'D', 'E', 'F', 'G']
    }
  },
  created () {
    let _this = this
    api.get('/ai/form', {}, function (res) {
      console.log(res)
      _this.form = res.d.show.entity
      _this.items = res.d.show.form
    })
  },
  mounted () {
  },
  methods: {
    submit () {
      let text = this.text
      let _this = this
      api.post('/ai/index', {text}, function (res) {
        console.log(res.d)
        _this.questions = res.d
      })
    },
    importQ (index) {
      console.log(index)
      let _this = this
      console.log(_this.form)
      let data = {
        subject: _this.form.subject,
        type: _this.form.type,
        point: _this.form.point,
        title: _this.questions[index].title,
        choice: _this.questions[index].choice,
        choiceSet: _this.questions[index].choiceSet,
        intro: _this.questions[index].intro,
        sort: _this.questions[index].sort
      }
      api.post('/ai/import', data, function (res) {
        console.log(res)
        if (res.s == 1) {
          _this.questions = com.arrayDelIndex(_this.questions,index)
          _this.$toast.message(res.i)
        }else {
          _this.$toast.error(res.i)
        }
      })
    }
  },
  watch: {}
}
</script>

<style scoped>

</style>
